import cv2


def main():
    cap = cv2.VideoCapture(u'./asset/demo.mp4')
    while True:
        ret, frame = cap.read()
        if not ret:
            break

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        xml_file = r'../venv/lib/python3.6/site-packages/cv2/data/haarcascade_frontalface_alt2.xml'

        face_cascade = cv2.CascadeClassifier(xml_file)
        faces = face_cascade.detectMultiScale(
            gray,
            scaleFactor=1.15,
            minNeighbors=5,
            minSize=(5, 5),
        )

        for (x, y, w, h) in faces:
            cv2.rectangle(frame, (x, y), (x + w, y + w), (0, 255, 0), 2)

        cv2.imshow("demo", frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()


if __name__ == '__main__':
    main()
